package sg.edu.nus.iss.vmcs.customer;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
* This class represents the control object that monitors the selection of drink 
* (drink brand) by a customer in the Customer Panel. It performs an action in 
* correspondance to the drink selected. It implements the interface ActionListener
* from Java AWT Event package.
*
*/

public class DrinkSelectionListener implements ActionListener {

	private  TransactionController transCtrl;

/**
 *  This constructor creates an instance of the Drink Selection Listener. It
 *  receives the reference for the Transaction Controller object as a parameter.
 * @param tCtrl Transaction Controller
 * @see TransactionController
 */	
	public DrinkSelectionListener(TransactionController tCtrl) {
		transCtrl = tCtrl;
	}

/**
 * Invoked when an action occurs in response to the button being pressed. 
 * Implemented as a part of interface.
 * @param e ActionEvent 
 * @see TransactionController#startTransaction(int)
 */	
	public void actionPerformed(ActionEvent e) {

		String cmd;
		int idx;
		Button btn;

		btn = (Button) e.getSource();
		cmd = btn.getActionCommand();
		idx = Integer.parseInt(cmd);
		
		transCtrl.startTransaction(idx);

	}

}
